import type {  Datum, EnterpriseDetail, EnterpriseListData, EnterpriseListParams, EnterpriseParams, EnterpriseTail, Industry, RentBuilding, RentParams } from "@/types/enterprise"
import service, { request } from "@/utils/reuqest"

export const getEnterpriseListAPI = (params: EnterpriseListParams) => {
  return request<EnterpriseListData>('/park/enterprise', 'GET', params)
}

/**
 * 获取行业列表
 * @returns
 */
export const getIndustryListAPI = () => {
  return request<Industry[]>('/park/industry')
}
/**
 * 添加企业
 * @returns
 */

export const createEnterpriseAPI=(data:EnterpriseParams)=>{
  return request('/park/enterprise','POST',data)
}
/**
 * 查看企业
 * @returns
 */

export const exterpriseAddAPI=(id:string)=>{
  return request<EnterpriseTail>(`/park/enterprise/${id}`)
}

/**
 * 编辑企业
 * @returns
 */
export const UpdateAddAPI=(data:Partial<EnterpriseTail>)=>{
  return request<EnterpriseTail>('/park/enterprise','PUT',data)
}

/**
 * 删除企业
 * @returns
 */
export const delEnterpriseAPI=(ids:string[])=>{
  return request(`/park/enterprise/${ids.join(',')}`,'DELETE')
}

/**
 * 获取空置中的楼宇(未租赁的)
 * @returns
 */
export const getRentBuildListAPI=()=>{
  return request<RentBuilding[]>('/park/rent/building')
}

/**
 * 给当前企业添加合同
 * @param {*} data
 * @returns
 */
export const  createRentAPI = (data: RentParams) => {
  return request('/park/enterprise/rent', 'POST', data)
}



/**
 * 获取企业下合同列表
 * @param {*} id
 * @returns
 */
export const getRentListAPI = (id: number) => {
  return request<Datum[]>(`/park/enterprise/rent/${id}`)
}


/**
 * 退租
 * @param {合同id} rentId
 * @returns
 */
export const outRentAPI = (rentId: string)=> {
  return request(`/park/enterprise/rent/${rentId}`, 'PUT')
}

/**
 * 删除合同
 * @param {合同id} rentId
 * @returns
 */
export const deleteRentAPI = (rentId: string)=> {
  return request(`/park/enterprise/rent/${rentId}`, 'DELETE')
}

/**
 * 获取企业详情
 * @param {*} id
 * @returns
 */
export const getEnterpriseDetailAPI = (id: string) => {
  return request<EnterpriseDetail>(`/park/enterprise/${id}`)
}
/*
*
*下载合同文件
/ */

export const downloadContractAPI = (id: number) => {
  // ❌ 普通的写法，解析成字符串是错误的
  // return request(`/download/${id}`)

  // ✅ 第二个范型参数为 Blob，请求配置中设置 responseType: 'blob'
  return service.request<null,Blob>({
    method:'GET',
    url:`/download/${id}`,
    responseType:'blob'
  })
}
